
% Graph
xGrid = Grids.x / Grids.x(1) ; % PercPopC ; % 


% Compute similar relative scale for JL/JF
smin = min(Params.delta .* zetaC) ;
smax = max(Params.delta .* zetaC) ;
fRmin = min(fC) ;
fRmax = max(fC) ;

sratio = smax/smin ;
fRratio = fRmax / fRmin ;
ratio = max(sratio,fRratio) ;

sl = [ 0.5 * smin , 1.05 * ratio * smin ] ;
fRl = [ 0.5 * fRmin , 1.05 * ratio * fRmin ] ;

if ishandle(2)
    close(2)
end

figure(2)
set(gcf,'Position',[100 100 1000 500])
nx = 2 ; ny = 3 ; fontsize = 14 ; factor = 0.9 ;

subplot(nx,ny,1)
plot1 = plot(xGrid , zeros(size(zetaC)),'Color',MyOrange,'LineStyle','-'); hold on;
%plot2 = plot(xGrid , tauVAadjInt / tauVAadjInt(end) - 1,'Color',MyBlue,'LineStyle','--'); hold on;
plot2 = plot(xGrid , GridsQO.tax / GridsQO.tax(end) - 1 ,'Color',MyBlue,'LineStyle','--'); hold on;
plot3 = plot(xGrid , GridsZ.tax / GridsZ.tax(end) - 1 ,'Color',OliveGreen,'LineStyle',':'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$\tau^*$','interpreter','latex')
title('Subsidy relative to top location','interpreter','latex','Fontsize',fontsize)
xlim([xGrid(1) xGrid(Grids.Nx)])
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid on
legend({'Laissez-faire','Quasi-optimal','EZ'},'Location','NorthEast','Interpreter','latex')
legend boxoff 
ylim([0,0.6])

subplot(nx,ny,2)
plot(xGrid,Params.delta .* zetaC,'Color',MyOrange); hold on;
plot(xGrid,Params.delta .* zetaQO,'Color',MyBlue,'LineStyle','--'); hold on;
plot(xGrid,Params.delta .* zetaZ,'Color',OliveGreen,'LineStyle',':'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$\delta / z$','interpreter','latex')
title('Job losing rate','interpreter','latex','Fontsize',fontsize)
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid on
xlim([xGrid(1) xGrid(Grids.Nx)])
% ylim(sl)
ylim([0.005,0.04])

subplot(nx,ny,3)
plot(xGrid,fC,'Color',MyOrange); hold on;
plot(xGrid,fQO,'Color',MyBlue,'LineStyle','--'); hold on;
plot(xGrid,fZ,'Color',OliveGreen,'LineStyle',':'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$f_R$','interpreter','latex')
title('Finding rate','interpreter','latex','Fontsize',fontsize)
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid on
xlim([xGrid(1) xGrid(Grids.Nx)])
% ylim([fRl(1) , 2 * fRl(2)])
ylim([0.05,0.4])

subplot(nx,ny,4)
plot(xGrid,uC,'Color',MyOrange); hold on;
plot(xGrid,uQO,'Color',MyBlue,'LineStyle','--'); hold on;
plot(xGrid,uZ,'Color',OliveGreen,'LineStyle',':'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$u$','interpreter','latex')
title('Unemployment rate','interpreter','latex','Fontsize',fontsize)
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid on
xlim([xGrid(1) xGrid(Grids.Nx)])


subplot(nx,ny,5)
plot(xGrid,LC,'Color',MyOrange); hold on;
plot(xGrid,LQO,'Color',MyBlue,'LineStyle','--'); hold on;
plot(xGrid,LZ,'Color',OliveGreen,'LineStyle',':'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$L$','interpreter','latex')
title('Average population density','interpreter','latex','Fontsize',fontsize)
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid on
xlim([xGrid(1) xGrid(Grids.Nx)])

subplot(nx,ny,6)
plot(xGrid,hC / hC(end) ,'Color',MyOrange); hold on;
plot(xGrid,hQO / hQO(end) ,'Color',MyBlue,'LineStyle','--'); hold on;
plot(xGrid,hZ / hZ(end) ,'Color',OliveGreen,'LineStyle',':'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$\overline{k}$','interpreter','latex')
title('Average human capital','interpreter','latex','Fontsize',fontsize)
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid on
xlim([xGrid(1) xGrid(Grids.Nx)])

if options.SaveResults

    % pdf
    filename = 'results/FigurePolicies' ;
    run printPDF.m ;
    
    % tiff
    exportgraphics(gcf,'results/FigurePolicies.tiff','Resolution',1000) 

end

hold off


%% optimal policy under heuristic

% optimal policy with heuristic (and the intermediate share adjustment)
tauVAheuristic = (sC ./ sC(end) ).^( ParamsC.alpha / ( 1 - ParamsC.alpha ) * 2 ) ;

cut = 0.00 ;
sum(popC(popC > cut))

figure(20)
set(gcf,'Position',[100 100 500 300])
fontsize = 14 ; factor = 0.9 ;

plot1 = plot(xGrid(popC > cut) , tauVA(popC > cut) - 1,'Color',MyBlue,'LineStyle','-'); hold on;
plot2 = plot(xGrid(popC > cut) , tauVAheuristic(popC > cut) - 1,'Color',MyOrange,'LineStyle','--'); hold on;
xlabel('$\ell(p,a)$','interpreter','latex')
ylabel('$\tau^*$','interpreter','latex')
xlim([xGrid(1) xGrid(Grids.Nx)])
AxisFonts(0.75*fontsize,fontsize,0.75*fontsize,fontsize)
grid off
legend({'Exact','Approximation'},'Location','NorthEast','Interpreter','latex','FontSize',fontsize)
legend boxoff 
ylim([0,0.6])

if options.SaveResults

    % pdf
    filename = 'results/PolicyHeuristic' ;
    run printPDF.m ;
    
    % tiff
    exportgraphics(gcf,'results/PolicyHeuristic.tiff','Resolution',1000) 

end

hold off

